<?php
namespace web\util;

class ExpressUtil {

    public static function query($orderNo) {
        $host = "https://wuliu.market.alicloudapi.com"; // api访问链接
        $path = "/kdi"; // API访问后缀
        $method = "GET";
        $appcode = "231bba1f2b1a4407891688012a4161b6"; // 替换成自己的阿里云appcode
        $headers = array();
        array_push($headers, "Authorization:APPCODE " . $appcode);

        $querys = "no=$orderNo&type=zto"; // 参数写在这里
        $bodys = "";
        $url = $host . $path . "?" . $querys; // url拼接

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl, CURLOPT_FAILONERROR, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HEADER, false);
        if (1 == strpos("$" . $host, "https://")) {
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        }
        $info = curl_getinfo($curl,CURLINFO_HTTP_CODE);
        var_dump($info);
        $result = curl_exec($curl);
        curl_close($curl);
        return json_decode($result, true);
    }

    /**
     * 订单状态
     * @param int $status
     * @return string
     */
    public static function getDeliveryStatusName($status) {
        switch ($status) {
            case 1:
                return '在途中';
            case 2:
                return '正在派件';
            case 3:
                return '已签收';
            case 4:
                return '派送失败';
        }
    }
}